<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style>
		body{
			background: #657A89 url() 0 0 no-repeat;
			overflow: hidden;
		}
		#img{
			display: block;
			position: relative;
			top: 0px;
			left:0px;
		}
	</style>
	<script>
		
		window.onload= function(){

			img = document.getElementById("img");
			btn = document.getElementById("btn");

			btn.onclick= function () {
				if(btn.value=="开始"){
					btn.value="停止";
					time = setInterval(run,50);

				}else{
					btn.value="开始";
					clearInterval(time);
				}
			}

			left = 0;
			fang = true;
			function run() {

				if(left>1300){
					fang = false;
					img.src = "dog.gif";
				}else if(left<-500){
					fang = true;
					img.src = "ren.gif";
				}

				if(fang){
					left+=10;
				}else{
					left-=10;
				}

				img.style.left = left+"px";
			}

		}


	</script>
</head>
<body>
	<input type="button" id="btn" value="开始">
	<img src="./ren.gif" id="img" alt="">
</body>
</html>